from zflow import *

# class MyOutport(ZGraph):
#     def __init__(self, name):
#         ZGrasph.__init__(self,name)  


class MyInport(ZGraph):
    def __init__(self, name):
        ZGraph.__init__(self,name)
        #控制信号
   
        self.add_ipad(ZDatum('wrt',1,wire))
        self.add_ipad(ZDatum('wrt_next',1,wire))
        self.add_opad(ZDatum('sa_answer',1,wire))

        self.add_ipad(ZDatum('data',16,register))
        #报文输入输出
        self.add_ipad(ZDatum('in',16,wire))
        self.add_opad(ZDatum('out',16,wire))
        # self.add(ZDatum('id',4,register))

        # self.add(ZDatum('data',8,register))

        #接口状态
        status=self.add_opad(ZDatum('free',1,register))
        status.init = '1'
        
        status.val = 'self.wrt == 1 & status == 1 ? 0: status'


        self.sa_answer.val = 'free'
        
        self.data.val = 'self.wrt==1 & status == 1 ? in: data'
        self.out.val = 'self.wrt_next==1  ? data: out'
        status.val ='self.wrt_next==1 ? 1: status'

        


if __name__ == '__main__':
    gen_graph_code([MyInport('')],ZVlogModuleTemplate)